from alg import Solution
import time
from gen import generate_multiple_test_cases


def run_test_case(stones, expected):
    sol = Solution()
    start_time = time.time()
    result = sol.canCross(stones)
    end_time = time.time()

    print(f"\nInput stones: {stones}")
    print(f"Expected result: {expected}")
    print(f"Actual result: {result}")
    print(f"Test {'passed' if result == expected else 'failed'}")
    print(f"Execution time: {(end_time - start_time) * 1000:.2f} ms")
    return result == expected


if __name__ == "__main__":
    # Example test cases
    test_cases = [
        ([0, 1, 3, 5, 6, 8, 12, 17], True),  # Can cross
        ([0, 1, 2, 3, 4, 8, 9, 11], False),  # Cannot cross
        ([0, 1, 3, 6, 10, 15, 21], True),  # Can cross (perfect steps)
        ([0, 2], False),  # Cannot make first jump
        ([0, 1, 3, 6, 7], False),  # Fail later jump
    ]

    print("Running predefined test cases:")
    passed = 0
    for i, (stones, expected) in enumerate(test_cases):
        print(f"\n{'=' * 30}")
        print(f"Test Case {i + 1}")
        print(f"{'=' * 30}")
        if run_test_case(stones, expected):
            passed += 1

    print(f"\nPredefined test cases: {passed}/{len(test_cases)} passed")

    # Random test cases
    print("\nRunning random test cases:")
    random_test_cases = generate_multiple_test_cases(5)
    random_passed = 0
    for i, (stones, expected) in enumerate(random_test_cases):
        print(f"\n{'=' * 30}")
        print(f"Random Test Case {i + 1}")
        print(f"{'=' * 30}")
        if run_test_case(stones, expected):
            random_passed += 1

    print(f"\nRandom test cases: {random_passed}/{len(random_test_cases)} passed")